﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using LoanCalculatorService.Models;

namespace LoanCalculatorService.Controllers
{
    public class LoansController : ApiController
    {
        Loan[] products = new Loan[] 
        { 
            new Loan { Interest = 3, _defaultStartDate= DateTime.Now }, 
             new Loan { Interest = 5, _defaultStartDate= DateTime.Now.AddMonths(1) }, 
        };

        public IEnumerable<Loan> GetAllLoans()
        {
            return products;
        }

        public IHttpActionResult GetLoan(int id)
        {
            var product = products.FirstOrDefault((p) => p.Interest == id);
            if (product == null)
            {
                return NotFound();
            }
            return Ok(product);
        }
        public double cal(double a, double b)
        {
            if (a < 0)
            {
                return 0;
            }
            return a + b;
        }
    }
}
